﻿<%@ WebHandler Language="C#" Class="dbAccess" %>
using System.Web.Configuration;
using System.Configuration;
using System;
using System.Web;

public class dbAccess : IHttpHandler
{
	string type;
	
	public void ProcessRequest(HttpContext context)
	{
		context.Response.ContentType = "application/json";
		
		type = context.Request.Form.Get("type");
		bool valid = false;
		string msg;
		switch( type )
		{
			case "deleteReply" :
				valid = deleteReply(int.Parse(context.Request.Form.Get("idx")), context.Request.Form.Get("psw"),out msg);
				break;
			default:
				return;
		}

		context.Response.Write(string.Format("{{\"valid\":{0},\"msg\":\"{1}\"}}", valid.ToString().ToLower(), msg));
		
	}
		
	public bool deleteReply(int idx, string psw, out string msg)
	{
		TimeCapsule.Member mb = new TimeCapsule.Member();
		TimeCapsule.dbAccess da = new TimeCapsule.dbAccess();
		if(mb.key == "") //비회원
		{
			if( da.DeactivateReply(idx, psw) )
			{
				msg = "성공";
				return true;
			}
			else
			{
				msg = "비밀번호가 올바르지 않습니다.";
				return false;
			}
			
		}
		else              //회원
		{
			if (da.DeactivateReply(mb.Idx, idx, mb.Role))
			{
				msg = "성공";
				return true;
			}
			else
			{
				msg = "올바르지 못한 접근입니다.";
				return false;
			}
			
		}
	}
	
	public bool IsReusable
	{
		get
		{
			return false;
		}
	}

}
